<html>
 <head>
  <title>Daftar Rekanan</title>
  <link href="../../css/lov.css" rel="stylesheet" type="text/css" />
  
  <script language="javascript" type="text/javascript">
   function selectRekan(id_leveransir,nama_leveransir,npwp_leveransir,alamat_leveransir){
	   window.parent.selectRekan(id_leveransir,nama_leveransir,npwp_leveransir,alamat_leveransir);
	   window.parent.tb_remove();
   }


  </script>

  <!-- Onblur OnFocus
<script type="text/javascript">
var search ='Search...';
window.onload =function (){
//inisialisai awal textbox
document.getElementById('search_name').value =search; //text/tulisan
document.getElementById('search_name').style.color ="#666666"; //color text
}

function tbFocus(textbox){
    if(textbox.value == search){
    textbox.value ="";
    textbox.style.color="#000000";
    }
}
function tbBlur(textbox){
    if(textbox.value == ""){
    textbox.value =search;
    textbox.style.color="#666666";
    }
}

</script>-->
 </head>
<body class="bodyLOV">

<?php
include '../../modul/general.php';
//Paging
$table = "m_leveransir";
$dataperhal = 10;
    if(isset($_GET['page'])){
        $noPage= $_GET['page'];}
    else{
        $noPage= 1;
    }
$start = ($noPage-1)*$dataperhal;

$search = $_POST['search_name'];
//if ($search=='Search...'){
//    $search = "";
//}
$SQL = "SELECT id_leveransir,nama_leveransir,npwp_leveransir,alamat_leveransir FROM $table";

// field seacrh
$sqlq = getRSq($SQL);
$jmlField = pg_num_fields($sqlq);
for ($x=0;$x<$jmlField;$x++){
    $namaField = pg_field_name($sqlq, $x);
    $cond .= "CAST(lower(".$namaField.") as TEXT) LIKE lower('%$search%') OR ";
}
$condition = substr($cond,0,strlen($cond)-3);
// end field search
if(isset($_POST['search'])){
        $noPage= 1;
	 $SQL .= " WHERE $condition";
         $SQL .= " ORDER BY id_leveransir ASC";
         if ($search==""){
         $SQL .= " OFFSET $start LIMIT $dataperhal ";
         }
 }else{
         $SQL .= " ORDER BY id_leveransir ASC";
         $SQL .= " OFFSET $start LIMIT $dataperhal ";
 }
 $query = getRS($SQL);
?>
<div class="big-border">
<div class="big-border-search">
<form action="" method="post">
 <div class="border-search">
 <input class="inputLOV" id="search_name" type="text" name="search_name" size="20" value="<?php echo $search; ?>" />
 <button type="submit" class="searchLOV" name="search">Search</button>
 </div>
 <!--<input class="search" type="submit" name="search" value="" />-->
</form>
</div>
    <div class="big-border-inside">
    <table class="tableLOV" width="500px" bgcolor="#000000" cellspacing="1" cellpadding="3">
            
            <?php 
            if ($query==""){
                echo "<div class='norecord'>No Record</div>";
            }else{
                echo "<tr bgcolor='#DDDDDD'>
                        <th>Id Leveransir</th>
                        <th>Name Leveransir</th>
                        <th>NPWP Leveransir</th>
                        <th>Alamat Leveransir</th>
                        
                </tr>";
            $query = getRSq($SQL);
            while($row = pg_fetch_object($query)): ?>
            <tr bgcolor="#FFFFFF">
                    <td align="center"><a href="javascript:selectRekan('<?=trim($row->id_leveransir)?>','<?=trim($row->nama_leveransir)?>','<?=trim($row->npwp_leveransir)?>','<?=trim($row->alamat_leveransir)?>')"><?=$row->id_leveransir?></a></td>
                    <td><?=trim($row->nama_leveransir)?></td>
                    <td><?=trim($row->npwp_leveransir)?></td>
                    <td><?=trim($row->alamat_leveransir)?></td>
                    
            </tr>
            <?php endwhile;
            }
            ?>

    </table>
    </div>

<div class="border-nopaging">
    <?php
    $query2 = "SELECT * From $table";
    $data2 = getRSq($query2);
    $jumData = pg_num_rows($data2);
    $jumPage = ceil($jumData/$dataperhal);
    $showPage = 0;
    if ($noPage > 1) echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage-1)."'>PREV</a>";
    for($page = 1; $page <= $jumPage; $page++)
        {
                 if ((($page >= $noPage-2) && ($page <= $noPage + 2)) || ($page == 1) || ($page == $jumPage))
                {
                    if (($showPage == 1) && ($page != 2))  echo "...";
                    if (($showPage != ($jumPage - 1)) && ($page == $jumPage))  echo "...";
                    if ($page == $noPage) echo " <b>".$page."</b> ";
                    else echo " <a href='".$_SERVER['PHP_SELF']."?page=".$page."'>".$page."</a> ";
                    $showPage = $page;
                 }
        }
    if ($noPage < $jumPage) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage+1)."'>NEXT</a>";
    ?>
</div>
</div>
</body>
</html>
